package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.LocalZxProvinceAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@AttrHandler(LocalZxProvinceAttrHandler.class)
public class LocalZxProvinceAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Autowired
    private OperateInstAttrService operateInstAttrService;

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        String cityFieldName = "";
        //省份
        if(KiteStringUtils.equals(attr.getFieldName(), "2_0000220")){
            cityFieldName = "2_0000221";
        }
        //省份（Z端）
        else if (KiteStringUtils.equals(attr.getFieldName(), "2_0000107")){
            cityFieldName = "2_0000109";
        }

        if(KiteStringUtils.equals(attr.getFieldName(), "2_0000220")
                && KiteStringUtils.isEmpty(attr.getPreValue())){
            return;
        }


        KiteAttr cityAttr = inst.getAttr(cityFieldName);
        operateInstAttrService.setAttrValue(inst, cityFieldName, "", data.getSceneInstId(), null);
        LocalAttrHelper.loadPlatformCity(attr.getValue(), cityAttr, inst.getSpecId());
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
